/*
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* openUBMC is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*         http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <gtest/gtest.h>
#include <test_utilities/test_base.h>

#include "drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_card.h"
#include "drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_gpu.h"
#include "drivers/pcie_gpu_card/innosilicon/awm_m11p/awm_m11p_memory.h"
#include <mc/engine.h>
#include <mc/common.h>

namespace drivers {
namespace pcie_gpu_card {
namespace innosilicon {
namespace awm_m11p_test {

class awm_m11p_test_service : public mc::engine::service {
public:
    awm_m11p_test_service(const std::string& name) : mc::engine::service(name) {}
};

// ========================= awm_m11p_card测试 =========================
class AwmM11pCardTest : public mc::test::TestWithEngine {
protected:
    static void SetUpTestSuite() {
        TestWithEngine::SetUpTestSuite();
        m_test_service = std::make_unique<awm_m11p_test_service>("bmc.openubmc.test_awm_m11p_card");
        m_test_service->init();
        m_test_service->start();
    }
    static void TearDownTestSuite() {
        m_test_service->stop();
        TestWithEngine::TearDownTestSuite();
    }
    void SetUp() override {}
    void TearDown() override {}
    static std::unique_ptr<awm_m11p_test_service> m_test_service;
};
std::unique_ptr<awm_m11p_test_service> AwmM11pCardTest::m_test_service;

// 测试基本 start/stop
TEST_F(AwmM11pCardTest, basic_start_stop) {
    dev::awm_m11p_card card;
    EXPECT_TRUE(card.start());
    EXPECT_TRUE(card.stop());
}
// 多次 start
TEST_F(AwmM11pCardTest, multiple_start_stop) {
    dev::awm_m11p_card card;
    for (int i = 0; i < 3; i++) {
        EXPECT_TRUE(card.start());
        EXPECT_TRUE(card.stop());
    }
}
// 多实例并发
TEST_F(AwmM11pCardTest, multi_instance) {
    std::vector<std::unique_ptr<dev::awm_m11p_card>> cards;
    for (int i = 0; i < 3; i++) {
        auto card = std::make_unique<dev::awm_m11p_card>();
        card->set_service(m_test_service.get());
        card->set_object_name(("card_" + std::to_string(i)).c_str());
        EXPECT_TRUE(card->start());
        cards.push_back(std::move(card));
    }
}

} // namespace awm_m11p_test
} // namespace innosilicon
} // namespace pcie_gpu_card
} // namespace drivers

